package com.controller;

import com.pojo.Goods;
import com.pojo.User;
import com.service.GoodsService;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;


import java.util.List;

@Controller("GoodsControllerImpl")
@RequestMapping("/Goods")
public class GoodsControllerImpl {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/add")
    public String add(Goods goods) {

        goodsService.add(goods);
        return "redirect:/register.jsp";
    }

    /*@RequestMapping("/update")
    public String update(Goods goods) {

        goodsService.add(goods);
        return "redirect:/register.jsp";
    }*/

    @RequestMapping("/query")
    public String query(Goods goods, Model model) {
        Goods goods1=goodsService.query(goods);
        model.addAttribute("goods",goods1);
        return "redirect:/register.jsp";
    }

    @RequestMapping("/selectAllGoods")
    public String selectAllGoods(Goods user, Model model) {

        List<Goods> allGoods = goodsService.selectAllGoods();
        model.addAttribute("allGoods", allGoods);

        return "success";
    }
}
